<template>
  <div class="app-container">
    <el-card>
      <div style="display: flex;align-items: center;justify-content: space-between">
        <span style="font-size: 18px;line-height: 18px">商品分类</span>
      </div>
      <div style="display: flex;">
        <el-tree :data="treeData" :props="defaultProps" value-key="id" style="width: 400px;" class="mr10 mt10"
           @node-click="handleQueryType" :default-expand-all="true" :highlight-current="true" node-key="label" draggable>
          <template #default="{ node, data }">
            <span class="custom-tree-node">
              <span>{{ data.nccStuName?`(${data.nccStuCode})`+ data.nccStuName:data.stuClassName }}</span>
              <span>
                <el-button v-if="data.children" type="text" @click="append('add',data)" link icon="el-icon-plus"
                  style="font-size: 12px">新增子分类</el-button>
                <el-button size="mini" v-if="!data.children" type="text" icon="el-icon-edit-outline" @click="append('edit', data)"
                  style="font-size: 12px">修改</el-button>
                  <el-button size="mini" v-if="!data.children" type="text" icon="el-icon-video-pause" @click.stop="stopTree(data)"
                    style="font-size: 12px">
                    <span v-if="data.enableState == 0">启用</span>
                    <span v-if="data.enableState == 1">停用</span>
                    </el-button>
              </span>
            </span>
          </template>
        </el-tree>
<!--        <el-table :data="goodTypeList" border height="605px">
          <el-table-column type="index" label="序号" align="center"> </el-table-column>
          <el-table-column prop="stoName" label="仓库名称" align="center"></el-table-column>
          <el-table-column prop="stoAreaName" label="库区名称" align="center"></el-table-column>
        </el-table>-->
      </div>
<!--      <el-pagination background layout=" total,prev, pager, next, sizes,jumper" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" :current-page="queryList.pageNum" :page-size="queryList.pageSize"
        :page-sizes="[10, 20, 50,100]" :total="total">
      </el-pagination>-->
    </el-card>
    <wareAdd ref="wareAddRef" :visible.sync="visible" @addSuccess="addSuccess" />
  </div>
</template>

<script>
  import wareAdd from "@/components/waresSort/wareAdd.vue"
  import {
    findTreeSkuTypeData,
    findBasicSkuTypeDetailByClassId,
    updateSkuTypeStatus//停用
  } from '@/api/basic/PersonnelInformation.js'
  export default {
    components: {
      wareAdd
    },
    data() {
      return {
        queryList: {
          name: '', //物料名称
          code: '', //物料编号
        },
        //goodTypeList: [], //el-table数据
        total: 0,
        visible: false,
        treeData: [],
        defaultProps: {
          children: 'children',
          label: 'nccStuName'
        }
      }
    },
    created() {
      this.getNccMaterialList();
      //获取table
      this.getTable();
    },
    methods: {
      getNccMaterialList() {
        findTreeSkuTypeData().then(response => {
          this.treeData = response.data;
        });
      },
      //点击树
      handleQueryType(event, nodeData) {
        let param = {
          stuClassId: event.stuClassId
        }
        if (event.stuClassId) {
          //this.getTable(param);
        }
      },
      //获取table
/*      getTable(data) {
        findBasicSkuTypeDetailByClassId(data).then(res => {
          this.goodTypeList = res.rows;
          this.total = res.total;
        })
      },*/
      //新增树信息
      append(type,data) {
        this.visible = true;
        this.$refs.wareAddRef.openDialog(type,data);
      },
      //停用
      stopTree(data){
        let param = {
          status:data.enableState == 1?0:1,
          stuClassId:data.stuClassId
        }
        updateSkuTypeStatus(param).then(res=>{
          this.$message.success(res.msg);
          this.getNccMaterialList()
        })
      },
      //新增/修改后刷新列表
      addSuccess() {
        this.getNccMaterialList();
      },
      clearAll() {
        this.queryList = {
          name: "",
          code: null,
        };
        this.getNccMaterialList();
      },
      filterDire() {
        this.getNccMaterialList()
      },

      addDialog(type, row) {
        this.visible = true;
        this.$refs.materialAddRef.openDialog(type, row);
      },
      handleSizeChange(newsize) {
        this.queryList.pageNum = 1
        this.queryList.pageSize = newsize
        this.getNccMaterialList()
      },
      handleCurrentChange(newpage) {
        this.queryList.pageNum = newpage
        this.getNccMaterialList()
      },
    }
  };
</script>

<style scoped>
  .app-container {
    padding: 20px;
  }

  .el-card {
    margin-bottom: 20px;
  }

  .btn el-button {
    margin-bottom: 20px;
  }

  .el-pagination {
    float: right;
    margin: 20px;
  }
  .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }
  .el-tree{
    height: 615px;
    overflow-y: auto;
  }
  /* 添加禁用状态的样式 */
  .disabled-text {
    color: #dcdcdc; /* 灰色，禁用状态下的颜色 */
    cursor: not-allowed; /* 禁用状态下的鼠标样式 */
  }
</style>
